<script>

/**
 * Orders Component
 */
export default {
  data() {
    return {
      ordersData: [
        {
          type: "MySQL",
          environment: "测试环境",
          IPaddress: "192.168.71.32",
          configure: "32Core/64GB/500GB",
          cpu: "52%",
          memory: "43%",
          disk: "35%",
          activeState: "正常",
          detectionTime: "刚刚",
        },
        {
          type: "Kafka",
          environment: "正式环境",
          IPaddress: "10.0.71.52",
          configure: "32Core/64GB/500GB",
          cpu: "45%",
          memory: "73%",
          disk: "45%",
          activeState: "异常",
          detectionTime: "刚刚",
        },
        {
          type: "JEE服务器",
          environment: "测试环境",
          IPaddress: "192.168.71.53",
          configure: "64Core/32GB/800GB",
          cpu: "90%",
          memory: "66%",
          disk: "64%",
          activeState: "正常",
          detectionTime: "1分钟前",
        },
        {
          type: "ElasticSearch",
          environment: "正式环境",
          IPaddress: "10.0.71.64",
          configure: "32Core/64GB/500GB",
          cpu: "81%",
          memory: "45%",
          disk: "73%",
          activeState: "异常",
          detectionTime: "2分钟前",
        },
        {
          type: "MongoDB",
          environment: "测试环境",
          IPaddress: "192.168.71.72",
          configure: "16Core/32GB/200GB",
          cpu: "65%",
          memory: "65%",
          disk: "67%",
          activeState: "正常",
          detectionTime: "3分钟前",
        },
        {
          type: "ClickHouse",
          environment: "正式环境",
          IPaddress: "10.0.71.55",
          configure: "32Core/64GB/500GB",
          cpu: "66%",
          memory: "77%",
          disk: "55%",
          activeState: "异常",
          detectionTime: "2分钟前",
        },
        {
          type: "Redis",
          environment: "正式环境",
          IPaddress: "10.0.71.22",
          configure: "16Core/32GB/500GB",
          cpu: "67%",
          memory: "65%",
          disk: "53%",
          activeState: "正常",
          detectionTime: "3分钟前",
        },
        {
          type: "kafka",
          environment: "正式环境",
          IPaddress: "10.0.71.21",
          configure: "16Core/32GB/500GB",
          cpu: "76%",
          memory: "54%",
          disk: "61%",
          activeState: "异常",
          detectionTime: "3分钟前",
        },
        {
          type: "vmware",
          environment: "正式环境",
          IPaddress: "10.0.71.34",
          configure: "16Core/32GB/500GB",
          cpu: "82%",
          memory: "45%",
          disk: "47%",
          activeState: "正常",
          detectionTime: "5分钟前",
        },
        {
          type: "中间件",
          environment: "测试环境",
          IPaddress: "192.168.71.32",
          configure: "32Core/64GB/500GB",
          cpu: "73%",
          memory: "65%",
          disk: "62%",
          activeState: "异常",
          detectionTime: "5分钟前",
        }
      ],
      totalRows: 100,
      currentPage: 1,
      perPage: 10,
      fields: [
        { key: "type", label: "服务器类型" },
        { key: "environment", label: "机器环境" },
        { key: "IPaddress", label: "IP地址" },
        { key: "configure", label: "机器配置" },
        { key: "cpu", label: "CPU使用" },
        { key: "memory", label: "内存使用" },
        { key: "disk", label: "磁盘使用" },
        { key: "activeState", label: "活动状态" },
        { key: "detectionTime", label: "检测时间" },
        { key: "viewDetail", label: "查看详情" }
      ],
    };
  },
  watch: {
    "currentPage": {
      handler(){
        console.log("触发更新");
      }
    }
  },
  methods: {
    /**
     * Search the table data with search input
     */
    onFiltered(filteredItems) {
      // Trigger pagination to update the number of buttons/pages due to filtering
      this.totalRows = filteredItems.length;
      this.currentPage = 1;
    },
    // 种子详情
    seedDetail(row){
      console.log(row);
      this.$router.push('/spider/siteDetail')
    },
  }
};
</script>

<template>
  <div class="card">
    <div class="card-body pt-0">
      <div class="allNum">
        <div class="searchNum">为您检索到<span>5,000+</span>条信息</div>
      </div>
      <div class="table-responsive">
        <b-table
          class="table-centered"
          :items="ordersData"
          :fields="fields"
          responsive="sm"
          :per-page="perPage"
          :current-page="1"
          thead-class="thead-light"
          @filtered="onFiltered"
        >
          <!-- <template v-slot:cell(name)="row">
            <a :href="row.item.domainName" target="_blank">{{row.value}}</a>
          </template> -->
          <template v-slot:cell(environment)="row">
            <div v-if="row.value=='正式环境'" class="badge font-size-12 badge-soft-primary">{{ row.value}}</div>
            <div v-if="row.value=='测试环境'" class="badge font-size-12 badge-soft-info">{{ row.value}}</div>
          </template>
          <template v-slot:cell(activeState)="row">
            <div v-if="row.value=='正常'" class="badge font-size-12 badge-soft-success">{{ row.value}}</div>
            <div v-if="row.value=='异常'" class="badge font-size-12 badge-soft-danger">{{ row.value}}</div>
          </template>
          <template v-slot:cell(viewDetail)>
            <span style="cursor: pointer;">密码</span>
            <span style="margin:0 3px;">|</span>
            <span style="cursor: pointer;">控制台</span>
            <span style="margin:0 3px;">|</span>
            <span style="cursor: pointer;">jvm</span>
          </template>
        </b-table>
      </div>
      <div class="row">
        <div class="col">
          <div class="dataTables_paginate paging_simple_numbers float-right">
            <ul class="pagination pagination-rounded mb-0">
              <!-- pagination -->
              <b-pagination v-model="currentPage" :total-rows="totalRows" :per-page="perPage"></b-pagination>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.table-centered{
  ::v-deep thead,::v-deep tbody{
    tr{
      th:last-child,td:last-child{
        text-align: right;
      }
    }
  }
}
.allNum{
  padding-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.searchNum{
  span{
    font-size: 1rem;
    color: #3444c1;
    margin: 0 4px;
    font-weight: 600;
  }
}
</style>

